//
//  WelcomeViewController.swift
//  WeiBoSwift
//
//  Created by 吴斌 on 2022/9/30.
//

import UIKit
import Kingfisher

class WelcomeViewController: UIViewController {
    // 拖线的属性
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var iconViewBottomCons: NSLayoutConstraint!
    
    // MARK: - 系统回调函数
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 0.设置头像
        let profileURLString = UserAccountViewModel.shareIntance.account?.avatar_large
        // ?? : 如果??前面的可选类型有值,那么将前面的可选类型进行解包并且赋值
        // 如果??前面的可选类型为nil,那么直接使用??后面的值
        let url = URL(string: profileURLString ?? "")
        
        iconView.kf.setImage(with: url, placeholder: UIImage(named: "logo"), options: nil, completionHandler: nil)
        
        // 1.改变约束的值
        iconViewBottomCons.constant = UIScreen.main.bounds.height - 250
        
        // 2.执行动画
        // Damping: 阻力系数
        // initialSpringVelocity:初始化速度
        UIView.animate(withDuration: 1.5, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5.0, options: []) {
            self.view.layoutIfNeeded()
        } completion: { _ in
            UIApplication.shared.keyWindow?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
        }
    }
    
}
